#! /bin/sh
# PCP QA Test No. 715
# Basic checkout of the Perl pmdasimple implementation.
#
# Copyright (c) 2013 Red Hat.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard filters
. ./common.product
. ./common.filter
. ./common.check

perl -e "use PCP::PMDA" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "perl PCP::PMDA module not installed"

_cleanup()
{
    _restore_pmda_install simple
    rm -f $tmp.*
    exit $status
}

status=1
trap "_cleanup" 0 1 2 3 15

# real QA test starts here
_prepare_pmda_install simple

echo
echo "=== $iam agent installation ==="
cat << End-of-File | $sudo ./Install -e >$tmp.out 2>&1
perl
End-of-File
# Check simple metrics have appeared ... X metrics and Y values
_filter_pmda_install <$tmp.out

check()
{
    iter=$1
    name=$2

    echo "fetch pmprobe #$iter - $name" | tee -a $here/$seq.full
    pmprobe -v $iam \
    | LC_COLLATE=POSIX sort > $tmp.pmprobe
    cat $tmp.pmprobe >>$here/$seq.full

    echo "check pmprobe #$iter - $name" | tee -a $here/$seq.full
    cat $tmp.pmprobe \
    | while read metric nv v1
    do
	if [ "$metric" = "simple.numfetch" ]
	then
	    echo "$metric shows $nv value(s), $v1 fetches so far"
	else
	    echo "$metric shows $nv value(s)"
        fi
    done
}

echo
echo "=== fetch and check values ==="
echo sec,min,hour > $tmp.conf && $sudo mv $tmp.conf simple.conf
check 1 defaults
echo sec,min > $tmp.conf && $sudo mv $tmp.conf simple.conf
check 2 twotimes
echo hour > $tmp.conf && $sudo mv $tmp.conf simple.conf
check 3 onetime
echo > $tmp.conf && $sudo mv $tmp.conf simple.conf
check 4 notime

# reset the clock back to the start state
echo sec,min,hour > $tmp.conf && $sudo mv $tmp.conf simple.conf

echo "=== remove $iam agent ==="
$sudo ./Remove >$tmp.out 2>&1
_filter_pmda_remove <$tmp.out

status=0
exit
